<template>
    <div class="resource">
      <div class="s-content ct">
        <!-- 面包屑导航 -->
        <el-breadcrumb class="head-nav" :separator-icon="ArrowRight">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/zygx' }">科普资料</el-breadcrumb-item>
          <el-breadcrumb-item>河南农技大讲堂</el-breadcrumb-item>
        </el-breadcrumb>
  
        <!-- 公益讲座 -->
        <div class="lecture-section">
          <div class="section-header">
            <div class="header-left">
              <img src="../../assets/resources/lecture-icon.png" alt="">
              <div class="header-title">河南农技大讲堂</div>
            </div>
          </div>
          <div class="lecture-cards">
            <div class="lecture-card" v-for="(item, index) in lectureData" :key="index" @click="goDetail(item)">
              <div class="card-image">
                <img :src="item.imageUrl || item.informationImage || '../../assets/resources/default-lecture.jpg'" alt="">
              </div>
              <div class="card-title">
                {{ item.title || item.informationTitle || '暂无标题' }}
              </div>
            </div>
          </div>
          
          <!-- 分页 -->
          <div class="pagination-container">
            <el-pagination
              v-model:current-page="currentPage"
              v-model:page-size="pageSize"
              :page-sizes="[10, 20, 30, 50]"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ArrowRight } from '@element-plus/icons-vue'
  import { pageInformation } from '@/api/home';
  import { useRouter } from 'vue-router';
  import { ref, onMounted } from 'vue'
  
  const router = useRouter();
  
  // 公益讲座数据
  const lectureData = ref([]);
  const currentPage = ref(1);
  const pageSize = ref(10);
  const total = ref(0);
  
  // 获取公益讲座数据
  const getLectureData = async() => {
    try {
      const params = {
        params: {
          status: true,
          category: 'henan_class'
        },
        page: {
          pageSize: pageSize.value,
          pageNum: currentPage.value,
        }
      }
      console.log('公益讲座请求参数:', params)
      const ret = await pageInformation(params)
      console.log('公益讲座API返回数据:', ret)
      lectureData.value = ret?.data?.list || [];
      total.value = ret?.data?.total || 0;
      console.log('处理后的数据:', lectureData.value)
    } catch (error) {
      console.error('获取公益讲座数据失败:', error)
    }
  }
  
  // 处理页码变化
  const handleCurrentChange = (val) => {
    currentPage.value = val;
    getLectureData();
  }
  
  // 处理每页数量变化
  const handleSizeChange = (val) => {
    pageSize.value = val;
    currentPage.value = 1;
    getLectureData();
  }
  
  // 跳转到详情页
  const goDetail = (item) => {
    window.open(item.content, '_blank');
    // router.push(`/job/jobdetail/${item.informationId}?type=information`)
  }
  
  // 页面加载时获取数据
  onMounted(() => {
    getLectureData();
  })
  </script>
  
  <style lang="scss" scoped>
  .resource {
    width: 100%;
    display: flex;
    flex-direction: column;
    color: #777;
    min-height: 900px;
    margin-bottom: 100px;
    overflow: hidden;
    flex: 1;
    background: #f8f8f8 url('../../assets/job/6.png') no-repeat 0 200px;
    
    .s-content {
      display: flex;
      flex-direction: column;
      background: #f8f8f8 url('../../assets/job/6.png') no-repeat 0 200px;
      min-height: 1000px;
      width: 100%;
      padding: 0 10%;
      margin-top: 40px;
      font-size: 24px;
    }
  
    .head-nav {
      height: 125px;
      display: flex;
      align-items: center;
      font-size: 24px;
    }
  
    // 通用标题栏样式
    .section-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20px 0;
      margin-bottom: 20px;
      position: relative;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 1px;
        background-color: #e0e0e0;
      }
      
      .header-left {
        display: flex;
        align-items: center;
        img {
          width: 50px;
          height: 50px;
          margin-right: 20px;
          object-fit: contain;
        }
        .header-title {
          font-size: 32px;
          font-weight: bold;
          color: #333;
        }
      }
    }
  
    // 公益讲座样式
    .lecture-section {
      margin-bottom: 60px;
      
      .lecture-cards {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
        padding-bottom: 30px;
        margin-top: 30px;
        
        .lecture-card {
          background: #fff;
          border-radius: 8px;
          box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
          overflow: hidden;
          cursor: pointer;
          transition: transform 0.2s;
          height: 420px;
          
          &:hover {
            transform: translateY(-5px);
          }
          
          .card-image {
            height: 350px;
            overflow: hidden;
            
            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }
          
          .card-title {
            font-size: 16px;
            font-weight: bold;
            color: #333;
            padding: 0 15px;
            text-align: center;
            line-height: 1.2;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            word-break: break-word;
            overflow: hidden;
            box-sizing: border-box;
          }
        }
      }
      
      .pagination-container {
        display: flex;
        justify-content: center;
        margin-top: 40px;
      }
    }
  }
  </style> 